<?php
// questo script aggiunge nella tabella manufacturer_to_store
// le marche inserite non presenti
 
// Configuration
//require_once('../config.php');

function save_cliente($registry, $customer_id) {

	// Database
	$db = $registry->get('db');
  
	$query = "
				SELECT
				  customer.cod_fisc_part_iva,
					customer.firstname,
					customer.lastname,
					customer.email,
					customer.telephone,
					customer.fax,
					customer.date_added,
					address.company,
					address.address_1,
					address.address_2,
					address.city,
					address.postcode,
					country.name,
					zone.name
				FROM customer, 
				     address, 
				     country,
				     zone
				where customer.customer_id = $customer_id
				and   customer.address_id = address.address_id
				and   country.country_id = address.country_id
				and   zone.zone_id = address.zone_id
				and   zone.country_id = address.country_id";
/**
 *        INTO OUTFILE '/var/www/opencart/var/download/cliente.txt'
        FIELDS TERMINATED BY ';'
        LINES TERMINATED BY '##\n'

 */
	
	$customers = $db->query($query);
	
	if ($customers->num_rows) {
  
		$fileCliente = DIR_SYSTEM . '../var/download/cliente.txt';
		
	  /* per ogni manufacturer_id estratto lo inserisco sulla manufacturer_to_store
	  ** per lo store 0
	  */
		
	  foreach ($customers->rows as $customer) {
	    
	  	$str = '';
	  	foreach ( $customer as $key => $value ) {
	  		$str .= $value .';';
	  	}
	  	
	  	$str .= "##\n";
	  	
	  	$handle = fopen($fileCliente, "w");
	  	if ($handle) {
	  		fwrite($handle, $str);
	  		fclose($handle);
	  	}
	  }
	}	
}